package easy

func CanThreePartsEqualSum(arr []int) bool {
	sum := 0
	n := len(arr)
	for i := 0; i < n; i++ {
		sum += arr[i]
	}
	if sum%3 != 0 {
		return false
	}
	target := sum / 3
	i, cur := 0, 0
	for i < n {
		cur += arr[i]
		if cur == target {
			break
		}
		i++
	}
	if cur != target {
		return false
	}
	j := i + 1
	for j < n-1 {
		cur += arr[j]
		if cur == 2*target {
			return true
		}
		j++
	}
	return false
}
